/**
  ******************************************************************************
  * @file    iap.h
  * @author  Puya Application Team
  * @brief   Header for iap.c module
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2020 Puya Semiconductor.
  * All rights reserved.</center></h2>
  *
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __IAP_H
#define __IAP_H

#define APP_ADDR                      (0x08002000UL)
#define VERSION                       (0x13)

#define ERROR_COMMAND                 (0xEC)  /* Error command */
#define ACK_BYTE                      (0x79)  /* Acknowledge Byte ID */
#define NACK_BYTE                     (0x1F)  /* No Acknowledge Byte ID */
#define START_BYTE                    (0x7F)  /* Start connect byte */
#define SYNC_BYTE                     (0x5A)  /* synchronization byte */

#define CMD_GET_COMMAND               (0x00)  /* Get commands command */
#define CMD_GET_VERSION               (0x01)  /* Get Version command */
#define CMD_GET_ID                    (0x02)  /* Get ID command */
#define CMD_GET_DEVICE_IDCODE         (0x03)  /* Get DEVICE_IDCODE command */
#define CMD_SET_BR                    (0x0B)  /* Configure baudrate for usart */
#define CMD_READ_MEMORY               (0x11)  /* Read Memory command */
#define CMD_WRITE_MEMORY              (0x31)  /* Write Memory command */
#define CMD_GO                        (0x21)  /* GO command */
#define CMD_READ_PROTECT              (0x82)  /* Readout Protect command */
#define CMD_READ_UNPROTECT            (0x92)  /* Readout Unprotect command */
#define CMD_EXT_ERASE_MEMORY          (0x44)  /* Erase Memory command */
#define CMD_WRITE_PROTECT             (0x63)  /* Write Protect command */
#define CMD_WRITE_UNPROTECT           (0x73)  /* Write Unprotect command */

#define FLASH_OPTR_RDP_LEVEL_0        (0xAA)
#define FLASH_OPTR_RDP_LEVEL_1        (0x55)
#define FLASH_OPTR_RDP_LEVEL_2        (0xCC)

/* Exported constants --------------------------------------------------------*/
/* Exported variable ------------------------------------------------------- */
/* Exported functions ------------------------------------------------------- */
void IAPInit(void);
void IAPProcess(void);
void JumpToAddress(uint32_t uiAddr);

#endif /* __BOOTLOADER_H */

/************************ (C) COPYRIGHT Puya Semiconductor *****END OF FILE****/
